public class test3 {
    //力扣  43.字符串相乘
    public String multiply(String num1, String num2) {
        if(num1.equals("0") || num2.equals("0"))  return "0";
        // char[] chara = num1.toCharArray();
        // char[] charb = num2.toCharArray();
        StringBuilder[] retarr = new StringBuilder[num1.length()];
        int i = 0;
        // int cur2 = charb.length-1;
        for(int cur1 = num1.length()-1;cur1>=0;cur1-- ){
            int tmp = num1.charAt(cur1)-'0';
            StringBuilder chengji = chengJi(num2,tmp);
            retarr[i++] = chengji;
        }
        for(int j = 0;j<retarr.length;j++){
            int j1 = j;
            while(j1!=0){
                retarr[j].append(0);
                j1--;
            }
        }
        StringBuilder ret = retarr[0];
        for(int i1 =1;i1<retarr.length;i1++){
            ret = sum(ret,retarr[i1]);
        }
        return ret.toString();

    }

    public StringBuilder chengJi(String str,int n){
        StringBuilder ret = new StringBuilder();
        int key = 0;
        for(int cur = str.length()-1;cur>=0;cur--){
            int tmp = str.charAt(cur)-'0';
            int ji = tmp*n;
            ret.append((ji+key)%10);
            key = (ji+key)/10;
        }
        if(key!=0){
            ret.append(key);
        }
        return ret.reverse();

    }

    public StringBuilder sum(StringBuilder sb1,StringBuilder sb2){
        StringBuilder ret = new StringBuilder();
        int key = 0;
        int cur1 = sb1.length()-1,cur2 = sb2.length()-1;
        while (true) {
            //第一个字符串
            if(cur1>=0){
                key+=sb1.charAt(cur1)-'0';
                cur1--;
            }
            //第二个字符串
            if(cur2>=0){
                key+=sb2.charAt(cur2)-'0';
                cur2--;
            }
            ret.append(key%10);
            key/=10;
            if(cur1<0 && cur2<0){
                break;
            }
        }
        if(key!=0){
            ret.append(key%10);

        }
        StringBuilder reverse = ret.reverse();
        return reverse;
    }
}
